<?php

namespace App\Http\Controllers;

use App\Http\Libs\Helper_Huanxin;
use App\Models\Activity;
use App\Models\Chatroom;
use App\Models\CityPartner;
use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Category;
use Illuminate\Pagination\LengthAwarePaginator as lPaginator;

class CityPartnerController extends CommonController
{
    /**
     * 获取城市合伙人列表
     */
    public function getIndex()
    {
        $lists = CityPartner::orderBy('id', 'desc')->paginate(10);

        return view('citypartner.index')->with('lists', $lists)->with('actions', $this->actions);
    }

    public function search(Request $request)
    {

        $data = $request->input();
        $lists = CityPartner::orderBy('id', 'desc');

        if (isset($data['name']) && $data['name'] != '') {
            $lists->where('name', 'like', '%' . $data['name'] . '%');
        }

        if (isset($data['tel']) && $data['tel'] != '') {
            $lists->where('tel', 'like', '%' . $data['tel'] . '%');
        }

        $lists = $lists->paginate(10);



        return view('citypartner.search')->with('lists', $lists)->with('name', $data['name'])
            ->with('tel', $data['tel'])->with('actions', $this->actions);
    }



    public function getCreate()
    {
        return view('citypartner.create');
    }


    public function getEdit(Request $request)
    {
        $data = $request->input();
        $list = CityPartner::where('id', $data['id'])->first();

        return view('citypartner.edit')->with('list', $list);
    }


    public function postCreate(Request $request)
    {
        $data = $request->input();
        unset($data['_token'], $data['formType']);
        CityPartner::create($data);

        return AjaxCallbackMessage('创建成功', true, url('citypartner/index'));
    }

    public function postEdit(Request $request)
    {
        $data = $request->input();
        unset($data['_token'], $data['formType']);
        CityPartner::where('id', $data['id'])->update($data);

        return AjaxCallbackMessage('编辑成功', true, url('citypartner/index'));
    }


}
